function avdVisibility() {
	var avd = document.getElementById("adminVeriBlock");
	var select = document.getElementById("role");
	if(select.value == "student") {
		avd.style.display = "none";
  	}
	else {
		avd.style.display = "block";
	}
} 

function checkPasswordStrength(password)
{
	var strengthElem = document.getElementById("passStrength");
	strengthElem.className = "plainText";
	if (password == "")
	{
		strengthElem.innerHTML = "";
	}
	else if (password.length < 4)
	{
		strengthElem.innerHTML = "Rookie";
		strengthElem.className = "rookie";
	}
	else if (password.length >= 13)
	{
		strengthElem.innerHTML = "Epic";
		strengthElem.className = "epic";
	}
	else if (password.length >= 10)
	{
		strengthElem.innerHTML = "Strong";
		strengthElem.className = "strong";
	}
	else if (password.length >= 7)
	{
		strengthElem.innerHTML = "Medium";
		strengthElem.className = "medium";
	}
	else if (password.length >= 4)
	{
		strengthElem.innerHTML = "Weak";
		strengthElem.className = "weak";
	}
}

function checkConfirm()
{
	// check that password == confirm
	var confirmElem = document.getElementById("confirmText");
	if (document.getElementById("password").value != document.getElementById("confirm").value)
	{
		confirmElem.innerHTML = "Passwords don't match!";
		return false;
	}
	confirmElem.innerHTML = "";
	return true;
}

function checkRequiredFields()
{
	// check that all required fields are filled in
	var legal = true;
	var errMsg = "This field is required!";
	if (document.getElementById("username").value == "")
	{
		document.getElementById("usernameText").innerHTML = errMsg;
		legal = false;
	}
	if (document.getElementById("password").value == "")
	{
		var strengthElem = document.getElementById("passStrength");
		if (document.getElementById("role").value != "student")
		{
			strengthElem.className = "errorText";
			strengthElem.innerHTML = errMsg;
			legal = false;
		}
		else
		{
			strengthElem.className = "plainText";
			strengthElem.innerHTML = "";
		}
	}
	if (document.getElementById("name").value == "")
	{
		document.getElementById("nameText").innerHTML = errMsg;
		legal = false;
	}
	if (document.getElementById("role").value == "administrator" && document.getElementById("adminVeri").value == "")
	{
		document.getElementById("veriText").innerHTML = errMsg;
		legal = false;
	}
	
	return legal;
}

function clearError(idName)
{
	var elem = document.getElementById(idName);
	if (elem.className == "errorText")
		elem.innerHTML = "";
}

function checkForm()
{
	var legal = true;
	legal = legal && checkConfirm();
	legal = legal && checkRequiredFields();
	return legal;
}
